import { setPcRem } from '@/utils/pxtorem';
import { debounce } from '@/utils/utils';
import { onBeforeUnmount, onMounted, onUnmounted } from 'vue';

export function useRemListener() {
    /**
     * 处理PC因延后处理rem而引起的闪烁
     */
    function handleVisibilitychange() {
        setTimeout(setPcRem);
    }

    onMounted(() => {
        setPcRem();
        window.addEventListener('resize', setPcRem);
        document.addEventListener('visibilitychange', handleVisibilitychange);
    });

    onBeforeUnmount(() => {
        window.removeEventListener('resize', setPcRem);
        document.removeEventListener('visibilitychange', handleVisibilitychange);
    });
}
